<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  body{
  }
  #demo {
  width: 100px;
  height:100px;
  /* background: #000; */
  /* background: linear-gradient( to  left,red  50%,Green 50%); */
}
</style>
<body>
  <div id="demo"></div>
  
  <script>
     let arr=[1,2,3,4,5,6,7,8]
     let a2=[]
     arr.forEach((item,i)=>{
       if(i%3==0&&i!=0){
         a2.push([arr[i-3],arr[i-2],arr[i-1]])
       }else if(i>arr.length-3){
         a2.push([arr[i-1],arr[i]])
       }
     })
     console.log(a2)
  </script>
</body>
</html>